﻿CREATE TRIGGER [tr_Tracker_Car_CheckStatus]
ON [dbo].[t_Tracker_Car] 
FOR INSERT, UPDATE,DELETE
AS

IF UPDATE(VIN) OR UPDATE(TrackerRequestID) RETURN

DECLARE @TrackerRequestID int,@Status sysname

SELECT  @TrackerRequestID = tr.ID, @Status = m.MenuName
FROM inserted AS i
INNER JOIN t_TrackerRequest tr ON i.VIN = tr.VIN
INNER JOIN t_Menu m ON m.MenuID = tr.StatusID

IF dbo.RequestStatus_Attr_LockTrackers(@TrackerRequestID,DEFAULT) = 0 RETURN

RAISERROR('Can''t change Tracker->Car info while in [%s] status.',16,1,@Status)
ROLLBACK TRAN

